package com.hdaccp.goodsprovider.controller;

import com.hdaccp.goodsprovider.dao.PtheorderDao;
import com.hdaccp.goodsprovider.dao.TheorderDao;
import com.hdaccp.goodsprovider.dao.theorderxxDao;
import com.hdaccp.goodsprovider.service.GoodsService;
import org.main.bean.POJO.*;
import org.main.bean.entity.Theorder;
import org.main.bean.entity.Theorderxx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/theorderinfo")
public class TheorderController {

    @Autowired
    private TheorderDao theorderDao;

    @Autowired
    private theorderxxDao theorderxxDao;
    @Autowired
    private PtheorderDao ptheorderDao;

    @RequestMapping("/upqueren/{OrderID}")
    @ResponseBody
    public Ptheorder query(@PathVariable("OrderID") int OrderID) {
        return ptheorderDao.getOne(OrderID);
    }

    @RequestMapping("/save/{OrderID}/{Ordershu}/{Yuanprice}/{Ordermoney}/{Ddstate}/{OrderBZ}/{GoodsID}/{Freight}/{Postal}/{Freightfs}/{Recipientxm}/{Recipientdh}/{Recipient}")
    @ResponseBody
    public String save(@PathVariable("OrderID") int OrderID,@PathVariable("Ordershu") int Ordershu,@PathVariable("Yuanprice") String Yuanprice,@PathVariable("Ordermoney") String Ordermoney,@PathVariable("Ddstate") String Ddstate,@PathVariable("OrderBZ") String OrderBZ,@PathVariable("GoodsID") int GoodsID,@PathVariable("Freight") int Freight,@PathVariable("Postal") int Postal,@PathVariable("Freightfs") String Freightfs,@PathVariable("Recipientxm") String Recipientxm,@PathVariable("Recipientdh") int Recipientdh,@PathVariable("Recipient") String Recipient) {
        String msg ="付款成功";
        Theorder theorder =new Theorder(OrderID,Ordershu,Yuanprice,Ordermoney,Ddstate,OrderBZ);
        Theorderxx theorderxx =new Theorderxx(OrderID,GoodsID,Freight,Postal,Freightfs,Recipientxm,Recipientdh,Recipient);

        try {
            theorderDao.save(theorder);
            theorderxxDao.save(theorderxx);
        } catch (Exception e) {
            msg = "付款失败";
        }

        return msg;
    }

    @RequestMapping("/upqueren/{OrderID}/{Ddstate}/{Confirm}")
    @ResponseBody
    public String update(@PathVariable("OrderID") int OrderID,@PathVariable("Ddstate") String Ddstate,@PathVariable("Confirm") String Confirm) {
     String msg="success";
     Theorder pGoods=theorderDao.getOne(OrderID);
     pGoods.setDdState(Ddstate);
     pGoods.setConfirm(Confirm);
        try {
            theorderDao.save(pGoods);
        } catch (Exception e) {
            msg = "shibai";
        }
        return msg;
    }


    /*@RequestMapping("/upqueren/{OrderID}/{Ddstate}/{Confirm}")
    @ResponseBody
    public String update1(@PathVariable("OrderID") int OrderID,@PathVariable("Ddstate") String Ddstate,@PathVariable("Confirm") String Confirm) {
        String msg="success";
        Theorder pGoods=theorderDao.getOne(OrderID);
        pGoods.setDdState(Ddstate);
        pGoods.setConfirm(Confirm);
        try {
            theorderDao.save(pGoods);
        } catch (Exception e) {
            msg = "shibai";
        }
        return msg;
    }
*/
}
